package edu.pg.ipse.kb.frame.core;

import java.util.HashMap;
import java.util.Map;

/**
 * 'Real World' data storage representation
 *
 */
public class Context {

    private Context() {
    }

    private final static Context instance = new Context();

    private final Map<Object, Object> parameters = new HashMap<Object, Object>();
    
    public static final Context getInstance() {
        return instance;
    }

    /**
     * Returns parameter according with input key
     *
     * @param key
     * @return parameter
     */
    public Object getParameter(Object key) {
        if (key != null) {
            return parameters.get(key);
        } else {
            return null;
        }
    }

    /**
     * Stores parameter in context
     *
     * @param key
     * @param value
     * @throws IllegalArgumentException if one of parameters is null
     */
    public void setParameter(Object key, Object value) {
        if (key == null || value == null) {
            throw new IllegalArgumentException("Null input parameter");
        }
        parameters.put(key, value);
    }

    /**
     * Clears parameters
     *
     */
    public void clearParameters() {
        this.parameters.clear();
    }

}
